package com.lujieni.consumer.config;

import com.lujieni.consumer.filter.ErpUserFilter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import java.util.Arrays;


/**
 * @author
 * @Title: FilterConfiguration
 * @Description:
 * @date 2022/11/21 5:37 下午
 */
@Configuration
public class FilterConfiguration {

    /**
     * ErpUserFilter只要这个Bean被注册了,该过滤器就会自动生效
     * 是能生效但会对所有的请求进行拦截,所以这里不能注册到spring容器
     * 中去,而是交给FilterRegistrationBean来注册
     * @return
     */
    //@Bean
    public ErpUserFilter createErpUserFilter(){
        return new ErpUserFilter();
    }

    @Bean
    public FilterRegistrationBean<ErpUserFilter> erpUserFilterRegistration(){
        FilterRegistrationBean<ErpUserFilter> filterFilterRegistrationBean = new FilterRegistrationBean<>();
        filterFilterRegistrationBean.setFilter(new ErpUserFilter());
        filterFilterRegistrationBean.setUrlPatterns(Arrays.asList("/token")); // 指定过滤器过滤的url
        return filterFilterRegistrationBean;
    }
}
